#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

// 语义化的类型
//UINT i
//SIZE i;
// typedef unsigned int SIZE;

// 定义一个结构
typedef struct _Student {
  char name[30];
  int age;
  int sex;
} Student;

// 结构变量.变量 对结构体内的元素进行访问
static void show(Student student){
  printf("name is %s\n",student.name);
  printf("sex is %s\n",student.sex == 1 ? "男":"女");
  printf("age is %d\n",student.age);
  // strcpy(student.name,"赵俊杰");

}

static void struct01(){
  Student student = {"邵明",43,1};
  show(student);
  printf("name is %s\n",student.name);
}


static void struct02(){
  Student students[2] = {{"邵明",43,1},{"赵俊杰",18,0}};
  int i;

  for(i = 0 ; i < 2; i++){
    show(students[i]);
  }
}

static void struct03(){
  Student * p = NULL;
  p = (Student *)malloc(sizeof(Student));
  strcpy((*p).name,"邵静雯");
  (*p).sex = 0;
  (*p).age = 13;
  show(*p);
  free(p);
}



static void struct04(){
  Student * p = NULL;
  p = (Student *)malloc(sizeof(Student));
  strcpy(p->name,"邵静雯");
  p->sex = 1;  // 通过指针访问结构体
  p->age = 13;
  show(*p);
  free(p);
}


static void struct05(){
  Student * p = NULL,*q;
  q = p = (Student *)malloc(sizeof(Student) * 10);
  
  printf("size is %d\n",sizeof(Student));

  strcpy(q->name,"邵静雯");
  q->sex = 1;  // 通过指针访问结构体
  q->age = 13;

  q++;
  
  strcpy(q->name,"邵明");
  q->sex = 1;  // 通过指针访问结构体
  q->age = 143;
  
  strcpy(p[2].name,"王志珏");
  p[2].sex = 1;  // 通过指针访问结构体
  p[2].age = 17;
  q++;
  q -= 2;
  show(*q);
  free(p);
}

// typedef void (*Sun_Proc)();

int main(int argc, char *argv[]) {
//  Sun_Proc p[2];
//  p[0]=struct01;
//  p[1]=struct02;
//  p[0]();
//  p[1]();

  struct05();
	return 0;
}
=